<cfparam name="Organization_ID" default="">
<cfset view = "certificates">
<cftry>
	<cfscript>
		scholarshipGateway = new assets.calgrants.com.gateway.ScholarshipGateway();
		scholarships = scholarshipGateway.query(Organization_ID = Organization_ID);
		certificateFiles = ArrayNew(1) />
		zipFile = Year(Now()) & "_Cash_for_College_Scholarship_Certificates_" & Organization_ID & ".zip";
	</cfscript>	
	<cfif scholarships.RecordCount gt 0>
	
		<cfloop query="scholarships">

			<cfset certificateFile = Scholarship_ID & ".pdf" />
			<cfset certificateExists = FileExists("C:\inetpub\assets\calgrants\ui\printable\scholarships\" & certificateFile) />
		
			<cfif NOT certificateExists>
	
				<cfset firstName = Trim(scholarship.getFirst_Name())>
				<cfset lastName = Trim(scholarship.getLast_Name())>
				<cfset fullName = firstName & " " & lastName />
	
				<cfpdfform action="populate" source="2014_Cash_For_College_Scholarship_Certificate_Form_v2.pdf" name="populatedForm">
					<cfpdfformparam name="firstName" value="#firstName#">
					<cfpdfformparam name="lastName" value="#lastName#">
				</cfpdfform>
				
				<cfpdf action="write" flatten="yes" source="populatedForm" destination="#certificateFile#" overwrite="yes">
	
			</cfif>
			
			<cfset certificateFiles = ArrayAppend(certificateFile) />
		
		</cfloop>
		
	<cfelse>
	
		<p>Invalid Scholarship</p>
		<cfabort>
		<cfset view = "invalidScholarship" />
	
	</cfif>

	<cfcatch type="any">
		<!--- bury the error --->
		<cfdump var="#cfcatch#">
		<cfabort>
		<cfset view = "error" />
	</cfcatch>

</cftry>


<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Cash for College Scholarship Certificate</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<meta name="description" content="Cash for College Scholars">
	<meta name="author" content="Syntric">
</head>

<body>
	<cfoutput>
		<br><br><br>
		<center>
		<div class="container">
			<div class="row">
				<div class="span12"></div>
					<div class="hero-unit">
						<cfswitch expression="#view#">
							<cfcase value="certificate">
									<!--- <h1>HELLO, #fullName#!</h1>
									<p>Click the link below to open your Scholarship Certificate.</p> --->
									<p><a href="#Scholarship_ID#.pdf" target="_blank" class="btn btn-large btn-primary">Open Certificate</a></p>
							</cfcase>
							<cfdefaultcase>
								<p>Scholarship certificate not found</p>
							</cfdefaultcase>
						</cfswitch>
					</div>
		
			</div>
		</div>
		</center>	
	</cfoutput>
</body>
</html>